package project.base.common.config

import com.xxl.job.core.executor.impl.XxlJobSpringExecutor
import org.springframework.beans.factory.annotation.Value
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration

/**
 * xxl-job定时任务配置
 * @author: 三味
 * @update: 2022/3/3 14:11
 */
//@Configuration
open class XxlJobConfig {
    @Value("\${xxl.job.admin.addresses}")
    private val adminAddresses: String? = null

    @Value("\${xxl.job.executor.appname}")
    private val appName: String? = null

    @Value("\${xxl.job.executor.ip}")
    private val ip: String? = null

    @Value("\${xxl.job.executor.port}")
    private val port = 0

    @Value("\${xxl.job.executor.logpath}")
    private val logPath: String? = null

    @Value("\${xxl.job.executor.logretentiondays}")
    private val logRetentionDays = 0

    @Bean(initMethod = "start", destroyMethod = "destroy")
    open fun xxlJobExecutor(): XxlJobSpringExecutor? {
        val xxlJobSpringExecutor = XxlJobSpringExecutor()
        xxlJobSpringExecutor.setAdminAddresses(adminAddresses)
        xxlJobSpringExecutor.setAppname(appName)
        xxlJobSpringExecutor.setIp(ip)
        xxlJobSpringExecutor.setPort(port)
        xxlJobSpringExecutor.setLogPath(logPath)
        xxlJobSpringExecutor.setLogRetentionDays(logRetentionDays)
        return xxlJobSpringExecutor
    }
}
